<template>
  <div class="Bookshelf">
    <Header />
    <div class="booknone" v-if="change">
      <div class="botto">
        <h1>书架空空如也</h1>
      </div>
      <!-- <div>
        <img src="bimg/books.jpeg" alt />
      </div>
      <div class="bslast">
        <span class="gold" @click="to">进入黄金屋</span>
        <span class="Jade" @click="to ">巧窥颜如玉</span>
      </div> -->
    </div>

    <!-- <debookshow class="bookshow" v-for="(item,index) in getbook" :key="index" :item="item" @click="it(index)" /> -->
    <!--  -->
   
  
  <div class="listtop" v-for="(item,index) in getbook" :key="index"  @click="read">
    <van-swipe-cell>
  <div class="List" >
    <div class="Lpic">
      <img :src="'bimg/'+item.pic" />
    </div>
    <div class="Lcenter">
      <p class="showtop">{{item.title}}</p>
      <p class="showmain">{{item.ather}}</p>
      <p class="showmain">{{item.category}}</p>
    </div>
  </div>
  <template #right>
    <van-button square text="删除" type="danger" class="delete-button" @click="go(index)"/>
  </template>
  </van-swipe-cell>
  </div>
    

    <foot />
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue'
import foot from "@/components/foot.vue";
import Header from "@/components/Header.vue";
import bookshow from "@/components/bookshow.vue";
import debookshow from "@/components/debookshow.vue";

export default {
  name: "Home",
  components: {
    foot,
    Header,
    bookshow,
    debookshow,
  },
  data() {
    return {
      getbook: [],
      change: false,
    };
  },
  methods: {
    changeStyle(index) {
      this.active = index; //实现第一种效果只需要这句代码  实现第二种效果就要加上外面的判断条件
    },
    it(index) {
      console.log(index);
    },
    to() {
      this.$router.push("/Home");
    },
    go(index){
      console.log(index)
      this.getbook.splice(index,1)
      localStorage.setItem('bookh', JSON.stringify(this.getbook))
    },
    read(){
      this.$router.push("/read");
    }
    
  },
  mounted() {
    // console.log(this.getbook)
    this.getbook = JSON.parse(localStorage.getItem("bookh"));
    // this.getbook = JSON.parse(localStorage.getItem("shop"));

    console.log(this.getbook);
    if(this.getbook==null){
     this.change = true;
    }else{
      if (this.getbook.length !== 0) {
      this.change = false;
      }else{
      this.change = true;
    }
    }
    
  },
};
</script>

<style  scoped>
.booknone {
  position: relative;
  height: 16rem;
  /* background-color: rgb(194, 250, 252); */
  top: 1.25rem;
  /* height: 18rem; */
  width: 100%;
  background-size: 100% 100%;

}
.Bookshelf img {
  height: 6rem;
  margin-left: 10%;
}
.botto {
  height: 1.2rem;
  width: 100%;
  color: #9d9d9d;
  text-align: center;
  line-height: 1.2rem;
  font-size: 0.5rem;
  position: relative;
  left: 0%;
  top: 40%;
}
.bslast {
  position: relative;
  top: 3rem;
  display: flex;
  text-align: center;
  line-height: 2rem;
  justify-content: space-around;
}
.gold {
  width: 40%;
  height: 2rem;
  color: #a1fd0e;
  font-size: 0.6rem;
}
.Jade {
  width: 40%;
  height: 2rem;
  color: #f8b2e3;
  font-size: 0.6rem;
}
.bList,
.List {
  display: flex;
  justify-content: space-around;
  padding: 10px;
  border-bottom: 0.01rem solid rgb(209, 201, 201);
}
.List img {
  height: 3rem;
  width: 80%;
  margin-left: 0.1rem;
}

.Lpic {
  display: flex;
  width: 30%;
  flex-direction: column;
}

.Lcenter {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 60%;
}

.Licon {
  align-self: center;
}
.showtop {
  font-size: 0.4rem;
  font-weight: 600;
}
.showmain {
  color: rgb(94, 79, 79, 0.6);
  font-size: 0.3rem;
  font-weight: 500;
}
.listtop{
  position: relative;
  top:1.25rem;
}
.van-button--danger {
    color: #fff;
    background-color: #ee0a24;
    border: 1px solid #ee0a24;
    height: 3.5rem;
}
</style>